package com.along.textdemo.manager;


import android.animation.ObjectAnimator;
import android.app.Dialog;
import android.content.Context;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.along.textdemo.R;
import com.along.textdemo.databinding.DialogDB;
import com.along.textdemo.databinding.DialogNewDB;
import com.along.textdemo.utils.ScreenUtils;

public class DialogManager {

    private DialogNewDB dialogDB;

    private static final String TAG = "DialogManager";
    private Dialog mDialog;
    private Context mContext;

    public DialogManager(Context mContext) {
        this.mContext = mContext;
    }

    /**
     * 显示对话框
     */
    public void showRecordeingDialog() {
        mDialog = new Dialog(mContext, R.style.Theme_AudioDialog);
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(mContext.LAYOUT_INFLATER_SERVICE);
        dialogDB = DialogNewDB.bind(inflater.inflate(R.layout.dialog_new, null));
        mDialog.setContentView(dialogDB.getRoot());

        Window window = mDialog.getWindow();

        window.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.BOTTOM);

        int width = ScreenUtils.getScreenWidth(mContext);

        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = (int)(width*0.8);
        lp.y = 500;  //设置出现的高度，距离底部
        window.setAttributes(lp);


        dialogDB.dialogBtnCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismissDialog();
            }
        });


        mDialog.show();
    }

    float aTime = 0.0f;
    String path="";

    /**
     * 获取音频信息
     * @param time
     * @param filePath
     */
    public void getAudio(float time, String filePath){
        aTime = time;
        path = filePath;
    }
    /**
     * 正在录制提示
     */
    public void recording() {
        if (mDialog != null && mDialog.isShowing()) {
            //todo 这里可以加载一个正在录音的动画

//            dialogDB.mainRecorderDialogIcon.setImageResource(R.mipmap.v3);
        }
    }
    public void showWave(){
        if (mDialog != null && mDialog.isShowing()) {
            dialogDB.line1.startRecord();
        }
    }
    public void stopWave(){
        if (mDialog != null && mDialog.isShowing()) {
            dialogDB.line1.stopRecord();
            dialogDB.line1.setVisibility(View.GONE);
        }
    }
    /**
     * 上滑展示，对话框内容
     */
    public void upShow(){
        if (mDialog != null && mDialog.isShowing()) {
            dialogDB.dialogBtnCancel.setVisibility(View.VISIBLE);
            dialogDB.line1.stopRecord();
            dialogDB.line1.setVisibility(View.GONE);
        }
    }


    /**
     * 发送按钮，对话框内容
     */
    public void sendToTitle(String audioPath){
        if (mDialog != null && mDialog.isShowing()) {
//           dialogDB.imageLayout.setVisibility(View.GONE);
//           dialogDB.btnLayout.setVisibility(View.VISIBLE);
            dialogDB.line1.stopRecord();
           dialogDB.dialogText.setText("语音路径："+audioPath);
        }
    }

    /**
     * 录音时间过短提示
     */
    public void tooShort() {
        if (mDialog != null && mDialog.isShowing()) {

            dialogDB.dialogText.setText(R.string.str_dialog_time_short);
        }
    }

    /**
     * 取消对话框
     */
    public void dismissDialog() {
        if (mDialog != null && mDialog.isShowing()) {
            mDialog.dismiss();
            mDialog = null;
        }
    }

    /**
     * 显示音量大小
     */
    public void updateVoiceLevel(int level) {
        if (mDialog != null && mDialog.isShowing()) {
            int resId = mContext.getResources().getIdentifier("v" + level, "mipmap", mContext.getPackageName());
//            dialogDB.mainRecorderDialogVoice.setImageResource(resId);
        }
    }



}

